package cn.laike.modules.dev.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import cn.laike.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.laike.modules.dev.entity.MobileMessageTemplateEntity;
import cn.laike.modules.dev.service.MobileMessageTemplateService;
import cn.laike.modules.sys.shiro.ShiroUtils;
import cn.laike.common.utils.PageUtils;
import cn.laike.common.utils.R;



/**
 * 短信验证模板
 *
 * @author ziye
 * @email 524748907@qq.com
 * @date 2019-02-20 15:09:14
 */
@RestController
@RequestMapping("dev/mobilemessagetemplate")
public class MobileMessageTemplateController {
    @Autowired
    private MobileMessageTemplateService mobileMessageTemplateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dev:mobilemessagetemplate:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = mobileMessageTemplateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dev:mobilemessagetemplate:info")
    public R info(@PathVariable("id") Integer id){
        MobileMessageTemplateEntity mobileMessageTemplate = mobileMessageTemplateService.selectById(id);

        return R.ok().put("mobileMessageTemplate", mobileMessageTemplate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dev:mobilemessagetemplate:save")
    public R save(@RequestBody MobileMessageTemplateEntity mobileMessageTemplate){
    	mobileMessageTemplate.setUid(ShiroUtils.getUserId());
    	mobileMessageTemplate.setCreateTime(new Date());
        mobileMessageTemplateService.insert(mobileMessageTemplate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dev:mobilemessagetemplate:update")
    public R update(@RequestBody MobileMessageTemplateEntity mobileMessageTemplate){
        ValidatorUtils.validateEntity(mobileMessageTemplate);
        mobileMessageTemplateService.updateAllColumnById(mobileMessageTemplate);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dev:mobilemessagetemplate:delete")
    public R delete(@RequestBody Integer[] ids){
        mobileMessageTemplateService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
